package org.seedframework.sharding.resource;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;



public class ShardingDataSourceBuilder {


    private final ShardingDataSource shardingDataSource;

    public ShardingDataSourceBuilder(String configs,
                                     String driverClassName,
                                     String jdbcUrl,
                                     String username,
                                     String password) {

        // init hikari-cp
        HikariConfig hikariConfig = configs == null ? new HikariConfig() : new HikariConfig(configs);
        hikariConfig.setDriverClassName(driverClassName);
        hikariConfig.setJdbcUrl(jdbcUrl);
        hikariConfig.setUsername(username);
        hikariConfig.setPassword(password);
        HikariDataSource dataSource = new HikariDataSource(hikariConfig);

        this.shardingDataSource = new ShardingDataSource(dataSource);

    }


    public ShardingDataSource build() {
        return shardingDataSource;
    }


}
